﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GGEditor.API.Documents
{
	public class SimpleDocument : IDocumentWriter, IDocumentReader
	{
		#region Implementation of IDocumentWriter

		private readonly IPropertiesWriter properties = new Properties();
		private readonly IList<IEntityWriter> entities = new List<IEntityWriter>();

		public IPropertiesWriter Properties
		{
			get { return properties; }
		}

		IEnumerable<IEntityReader> IDocumentReader.Entities
		{
			get
			{
				foreach (var entity in entities)
				{
					yield return entity;
				}
			}
		}

		public event DocumentPropertyChangedEventHandler PropertyChanged;

		public event EntityChangedEventHandler EntityAdded;

		public event EntityChangedEventHandler EntityRemoved;

		IPropertiesReader IDocumentReader.Properties
		{
			get { return Properties; }
		}

		IEnumerable<IEntityWriter> IDocumentWriter.Entities
		{
			get
			{
				foreach (var entity in entities)
				{
					yield return entity;
				}
			}
		}

		public void AddEntity(IEntityWriter entity)
		{
			entities.Add(entity);
		}

		public void RemoveEntity(IEntityWriter entity)
		{
			entities.Remove(entity);
		}

		#endregion
	}

	public class SimpleEntity : IEntityWriter, IEntityReader
	{
		private readonly IPropertiesWriter properties = new Properties();

		#region Implementation of IEntityWriter

		public IPropertiesWriter Properties
		{
			get { return properties; }
		}

		public event EntityPropertyChangedEventHandler PropertyChanged;

		#endregion

		#region Implementation of IEntityReader

		IPropertiesReader IEntityReader.Properties
		{
			get { return Properties; }
		}

		#endregion
	}


}
